package com.dzm.xgb.core.factory;

import cn.hutool.core.util.StrUtil;
import com.dzm.common.exception.BusinessException;
import com.dzm.xgb.core.strategy.ReturnHandler;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 作者：Dzm
 * 时间：2024-09-27-11:56
 * 功能：
 */

public class ReturnHandlerFactory {

    private static final Map<String, ReturnHandler> map = new HashMap<>();

    public static ReturnHandler getReturnHandler(String handlerKey) {
        return map.get(handlerKey);
    }

    public static void registerReturnHandler(String handlerKey, ReturnHandler handler) {
        if(StrUtil.isBlank(handlerKey) || handler == null) {
            throw new BusinessException("缓存注册异常！");
        }
        map.put(handlerKey, handler);
    }
}
